package com.snapan.es.entity;

import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.*;

import java.util.Date;

/**
 * ES 索引实体：对应 file_share 索引（关联 user_file + file_share 分表）
 */
@Document(indexName = "snapan_file_share", createIndex = true)
// 通过 @Setting 定义自定义分词器（解决中文后缀、特殊符号拆分问题）
@Setting(settingPath = "elasticsearch-settings.json")
public class FileShareDocument {
    @Id
    private Long id;

    @Field(type = FieldType.Long)
    private Long userId;

    @Field(type = FieldType.Long)
    private Long fileId;

    // 子字段名：fileName.en
    // 子字段：英文分词（拆分单词和字母）
    // 对应 user_file.file_name（用户自定义文件名搜索）
    // 文件名：中文主字段（IK 分词） + 英文子字段（standard 分词）
    @MultiField(
            mainField = @Field(
                    type = FieldType.Text,
                    analyzer = "fileName_light_analyzer", // 新增的轻量分词器（索引时）
                    searchAnalyzer = "fileName_light_search_analyzer", // 新增的轻量搜索分词器
                    norms = false
            ),
            otherFields = {
                    @InnerField(
                            suffix = "en",
                            type = FieldType.Text,
                            analyzer = "standard",
                            searchAnalyzer = "standard",
                            norms = false
                    )
            }
    )
    private String fileName;

    @Field(type = FieldType.Keyword)
    private String shareCode;

    @Field(type = FieldType.Date, pattern = "yyyy-MM-dd HH:mm:ss")
    private Date expireTime;

    @Field(type = FieldType.Keyword)
    private String password;

    @Field(type = FieldType.Byte)
    private Byte status;

    @Field(type = FieldType.Date, pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;

    @Field(type = FieldType.Long)
    private Long fileSize;

    @Field(type = FieldType.Keyword) // 对应 file_base.suffix（后缀筛选，如 .txt）
    private String fileSuffix;



    public Long getFileSize() {
        return fileSize;
    }

    public void setFileSize(Long fileSize) {
        this.fileSize = fileSize;
    }

    public String getFileSuffix() {
        return fileSuffix;
    }

    public void setFileSuffix(String fileSuffix) {
        this.fileSuffix = fileSuffix;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Long getFileId() {
        return fileId;
    }

    public void setFileId(Long fileId) {
        this.fileId = fileId;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public String getShareCode() {
        return shareCode;
    }

    public void setShareCode(String shareCode) {
        this.shareCode = shareCode;
    }

    public Date getExpireTime() {
        return expireTime;
    }

    public void setExpireTime(Date expireTime) {
        this.expireTime = expireTime;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Byte getStatus() {
        return status;
    }

    public void setStatus(Byte status) {
        this.status = status;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

}
